Fix pre-weights ignoring dit_quant_scheme (fp8 dtype mismatch) - #1470
Open
li-lizhe wants to merge 1 commit into
Open
Fix pre-weights ignoring dit_quant_scheme (fp8 dtype mismatch)#1470li-lizhe wants to merge 1 commit into
li-lizhe wants to merge 1 commit into
Conversation
ZImagePreWeights hard-coded its matmul layers (img_in / txt_in /
timestep embedder) to the "Default" scheme, unlike ZImagePostWeights
and ZImageTransformerWeights which follow config["dit_quant_scheme"].
With a pre-quantized FP8 checkpoint (e.g.
qwen_image_edit_2509_fp8_e4m3fn_scaled.safetensors), all_x_embedder is
stored as float8_e4m3fn but img_in still runs the Default addmm path,
so the bf16 activation and the fp8 weight fail with:
RuntimeError: self and mat2 must have the same dtype,
but got BFloat16 and Float8_e4m3fn
Align pre-weights with post/transformer weights: resolve mm_type once
from config and register every matmul layer via
MM_WEIGHT_REGISTER[self.mm_type].
Fixes ModelTC#1439
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Running a pre-quantized FP8 checkpoint (e.g.
qwen_image_edit_2509_fp8_e4m3fn_scaled.safetensors) withdit_quant_scheme: fp8-sglcrashes on the very first matmul:Root cause
ZImagePreWeightshard-codes its matmul layers (img_in/txt_in/ timestep embedder) to the"Default"scheme:while
ZImagePostWeightsandZImageTransformerWeightsboth resolveconfig["dit_quant_scheme"]and register throughMM_WEIGHT_REGISTER[self.mm_type].So with a quantized checkpoint,
all_x_embedder(and the other pre layers) load theirfloat8_e4m3fnweights but run theDefaulttorch.addmmpath — a bf16 activation multiplied against an fp8 weight.Fix
Align
ZImagePreWeightswith the other two weights classes: resolvemm_typeonce and register every matmul layer throughMM_WEIGHT_REGISTER[self.mm_type]. Thex_pad_token/cap_pad_tokentensor registrations are left untouched.Verification
python -m py_compilepasses.ZImagePreWeightsmatmul layers now followself.mm_type, matchingZImagePostWeights(which was already correct)._scaled_mm/ cutlass) is CUDA-specific, so I could not run end-to-end FP8 inference here. The change simply routes the pre-embedding matmuls through the same quantized/mm dispatch the maintainer already uses for post/transformer weights, which resolves the dtype mismatch on the reported setup.Fixes #1439